package com.shlh.saas.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.shlh.saas.entity.User;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

/**
 * saas模块的用户Mapper接口
 */
@Mapper
public interface UserMapper extends BaseMapper<User> {
    /**
     * 根据用户名查询用户
     * @param username 用户名
     * @return 用户对象
     */
    @Select("SELECT * FROM users WHERE username = #{username} AND is_deleted = 0")
    User findByUsername(@Param("username") String username);

    /**
     * 根据手机号查询用户
     * @param phone 手机号
     * @return 用户对象
     */
    @Select("SELECT * FROM users WHERE phone = #{phone} AND is_deleted = 0")
    User findByPhone(@Param("phone") String phone);

    /**
     * 根据用户ID更新用户信息
     */
    int updateUserById(User user);
    
    /**
     * 自定义插入方法（直接SQL插入）
     */
    int insertUser(User user);
    
    /**
     * 根据手机号查询用户
     */
    @Select("SELECT * FROM users WHERE phone = #{phone} AND is_deleted = 0")
    User selectByPhone(@Param("phone") String phone);
    
    /**
     * 根据用户名查询用户
     */
    @Select("SELECT * FROM users WHERE username = #{username} AND is_deleted = 0")
    User selectByUsername(@Param("username") String username);
} 